package com.ruoyi.campus.controller;

import com.ruoyi.campus.domain.Campus;
import com.ruoyi.campus.domain.vo.CampusVO;
import com.ruoyi.campus.domain.vo.UserRoleVO;
import com.ruoyi.campus.service.ICampusService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 校区列表Controller
 * 
 * @author ruoyi
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/campus/campusInfo")
public class CampusController extends BaseController
{
    @Autowired
    private ICampusService campusService;
    /**
     * 查询所有校区列表
     */

    @GetMapping("/list")
    public TableDataInfo list(CampusVO campusvo)
    {
        startPage();
        List<CampusVO> list = campusService.selectCampusList(campusvo);
        // System.out.println("==============="+list);
        return getDataTable(list);
    }
    /**
     * 查询校区列表列表
     */
    @GetMapping("/listAllCampus")
    public AjaxResult listAllCampus()
    {
        List<Campus> list = campusService.listAllCampus();
        return success(list);
    }

    // /**
    //  * 查询校区列表列表
    //  */
    // @PreAuthorize("@ss.hasPermi('campus:campusInfo:campusList')")
    // @GetMapping("/campusList")
    // public TableDataInfo list(Campus campus)
    // {
    //     startPage();
    //     List<Campus> list = campusService.selectCampusList(campus);
    //     return getDataTable(list);
    // }

    /**
     * 导出校区列表列表
     */
    @PreAuthorize("@ss.hasPermi('campus:campusInfo:export')")
    @Log(title = "校区列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CampusVO campusvo)
    {
        List<CampusVO> list = campusService.selectCampusList(campusvo);
        ExcelUtil<CampusVO> util = new ExcelUtil<CampusVO>(CampusVO.class);
        util.exportExcel(response, list, "校区列表数据");
    }

    /**
     * 获取校区列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('campus:campusInfo:query')")
    @GetMapping(value = "/{campusId}")
    public AjaxResult getInfo(@PathVariable("campusId") Integer campusId)
    {
        return success(campusService.selectCampusByCampusId(campusId));
    }

    /**
     * 新增校区列表
     */
    @PreAuthorize("@ss.hasPermi('campus:campusInfo:add')")
    @Log(title = "校区列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Campus campus)
    {
        return toAjax(campusService.insertCampus(campus));
    }

    /**
     * 修改校区列表
     */
    @PreAuthorize("@ss.hasPermi('campus:campusInfo:edit')")
    @Log(title = "校区列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Campus campus)
    {
        return toAjax(campusService.updateCampus(campus));
    }

    /**
     * 删除校区列表
     */
    @PreAuthorize("@ss.hasPermi('campus:campusInfo:remove')")
    @Log(title = "校区列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{campusIds}")
    public AjaxResult remove(@PathVariable Integer[] campusIds)
    {
        return toAjax(campusService.deleteCampusByCampusIds(campusIds));
    }

    /**
     * 查询可分销的校区列表
     */
    @GetMapping("/distributionList")
    public AjaxResult getDistributionCampusList() {
        List<Campus> list = campusService.getDistributionCampusList();
        return AjaxResult.success(list);
    }

    /**
     * 查询校长列表
     */
    @GetMapping("/headmasterList")
    public AjaxResult headmasterList() {
        List<UserRoleVO> headmasterList = campusService.headmasterList();
        return AjaxResult.success(headmasterList);
    }
}
